package com.daviteq.fw.service;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.daviteq.fw.controller.form.LoginForm;
import com.daviteq.fw.dao.core.AccountDao;
import com.eaio.uuid.UUID;

@Service
public class AccountService {
    @Autowired
    private AccountDao accountDao;

    public boolean isAuthenticated(LoginForm form) {
        try {
            accountDao.init();
            Map<String, String> info = new HashMap<String, String>(3);
            info.put("email", "chaudh76@gmail.com");
            info.put("fullname", "Dinh Hong Chau");
            info.put("password", "iconfig123");
            accountDao.insert(new UUID().toString(), info);
            
            String password = accountDao.readSingleColumnValue(form.getUserName(), "password");
            return password.equals(form.getPassword());
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
